package com.gopay.scheduler.job;

import com.gopay.common.constants.fund.FundFileSourceConstants;
import com.gopay.common.constants.holiday.HolidayType;
import com.gopay.common.domain.fund.vo.FileBizParam;
import com.gopay.common.util.DateUtils;
import com.gopay.remote.cps.holiday.HolidayRemoteService;
import com.gopay.remote.fundcps.service.FileHandlerService;
import com.gopay.scheduler.GopayBaseJob;
import com.gopay.scheduler.service.fund.FundBaseOperateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 基金公司T日提供的赎回对账文件，国付宝以此文件提前一天进行对账
 * @author baiyunpeng
 * @2016年7月14日 下午3:36:05  www.gopay.com.cn Inc.All rights reserved.
 */
public class FundRedeemCheckFileJob extends GopayBaseJob {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource(name = "fileHandlerService")
    private FileHandlerService fundFileRemoteService;
    @Autowired
    private FundBaseOperateService operateService;
    @Resource(name = "holidayRemoteService")
    private HolidayRemoteService holidayRemoteService;

    @Override
    public void doJobInternal() {
        try {
            if(!holidayRemoteService.isHoliday(new Date(), HolidayType.FUND_COMPANY)) {
                logger.info("与基金公司赎回分红结果对账文件生成定时任务开始！=============" + DateUtils.format(new Date()));
                String settleDay = DateUtils.format(new Date(), "yyyyMMdd");
                String res = fundFileRemoteService.redeemCheck(
                        new FileBizParam(settleDay, operateService.queryAllFundCorp(), FundFileSourceConstants.CORN));
                logger.info("与基金公司赎回分红结果对账文件生成定时任务结束  :  " + res);
            }
        } catch (Exception e) {
            logger.error("与基金公司赎回分红结果对账文件生成定时任务"+e.getMessage(),e);
        }
    }
}
